/*
 * Quadtree.h
 *
 *  Created on: 2009/01/22
 *      Author: Yongshik Cho
 */

#ifndef QUADTREE_H_
#define QUADTREE_H_

#include <map>
#include <vector>

#ifndef PREREQUISITES_H_
#	include "core/Prerequisites.h"
#endif

#ifndef RENDERABLE_H_
#	include "active/Renderable.h"
#endif


class Rect2D;

class Quadtree
{
public:
	static const float _DEFAULT_MIN_QUAD_WIDTH;
	static const float _DEFAULT_MIN_QUAD_HEIGHT;

public:
	Quadtree(Quadtree* parent, const Vector2D& p1, const Vector2D& p2);
	Quadtree(Quadtree* parent, const Rect2D& rect);
	virtual ~Quadtree();

public:
	const bool addRenderable(Renderable* r);
	void subRenderable(Renderable* r);
	Quadtree* getQuadtree(Renderable* r);
	Rect2D* getRect(Renderable* r);
	void clear();

	const uint32 getRenderableCount();

protected:
	typedef vector<Renderable*>						RenderableType;
	typedef map<Quadtree*, RenderableType*>			QuadtreeType;

	Quadtree*			mParent;

	Quadtree* 			mLeftTop;
	Quadtree* 			mRightTop;
	Quadtree* 			mLeftBottom;
	Quadtree* 			mRightBottom;

	Rect2D*				mRect;
	QuadtreeType		mRenderables;
};

#endif /* QUADTREE_H_ */
